package com.gxgeek.javabasic.base.string;

import com.alibaba.fastjson.JSON;

/**
 * @author gaoxing
 * @create 2018-08-20 下午4:54
 */
public class ReplaceTest {
    public static void main(String[] args) {
//        System.out.println("1"+"\n");
//        System.out.println("2"+"\\n");
//        System.out.println("3"+"\\\n");
//        System.out.println("4"+"\\\\n");
//        System.out.println("\\\\");
//
        String a = "[{\"key\":\"姓名\",\"value\":\"XX\"},{\"key\":\"资质\",\"value\":\"从事贵金属投资行业10年\n" +
                "国家期货二级分析师\n" +
                "上金所荣誉长老\"},{\"key\":\"其他\",\"value\":\"\"}]";
        System.out.println(a);
        System.out.println("~~~~~~~~~~~~~~~~~~~~");
        System.out.println(a.replaceAll("\n","\\n"));
        System.out.println("~~~~~~~~~~~~~~~~~~~~");
//        System.out.println(a.replaceAll("\n","\\n"));
        System.out.println("~~~~~~~~~~~~~~~~~~~~");
        System.out.println(a.replaceAll("\n","\\\\n"));
//        System.out.println(JSON.parse(a.replaceAll("\\\\","\\\\")));
//        System.out.println((a.replaceAll("\\\\","\\\\")));

//        System.out.println(stringToInt("A"));
//        System.out.println(stringToInt("B"));
//        System.out.println(stringToInt("C"));
//        System.out.println(stringToInt("ABC"));
//        System.out.println(Integer.parseInt("A"));
    }

    public static int stringToInt(String str) {
        int result=0;
        char[] ch=str.toCharArray();
        int len=ch.length;
        for(int i=0;i<len;i++) {
            result+=(((int)ch[i]-'0')*Math.pow(10, len-1-i));
        }
        return result;
    }

}
